package com.hzgj.bcl.soa.command;

import com.google.common.collect.Maps;
import com.hzgj.bcl.soa.collector.JmxCollector;
import com.hzgj.bcl.soa.util.Constants;

import java.util.Map;

/**
 * Created by warning on 2016/12/1.
 */
public class RemoteStatsCommand extends JmxInvokeCommand {


    @Override
    public String getName() {
        return "stats";
    }

    @Override
    Map<String, Object> jmxInvoke(JmxCollector jmxCollector, CommandOptions commandOptions, String host, String port) {
        Map<String, Object> result = Maps.newHashMap();
        try {
            result.put("status", "success");
            result.put("queueSize", jmxCollector.invokeWithoutParam(Constants.OBJECTNAME_PREFIX + Constants.OBJECTNAME_STATS + ",name = remote", "getQueueSize").toString());
        } catch (Exception e) {
            logger.error("{}", e);
            result.put("status", "failure");
            result.put("msg", e.getMessage());
            result.put("queueSize", 0);
        }
        return result;
    }
}
